home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / intuisup.lha / Intuisup / source.lha / Editor / project.c < prev    next >
C/C++ Source or Header  |  1992-10-02  |  16KB  |  686 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: project.c
  6.  *    Created ..: Sunday 22-Dec-91 21:22:52
  7.  *    Revision .: 0
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    22-Dec-91   Torsten Jürgeleit      Created this file!
  12.  *
  13.  ****************************************************************************
  14.  *
  15.  *    Project part
  16.  *
  17.  * $Revision Header ********************************************************/
  18.  
  19.  /* Includes */
  20.  
  21. #include "includes.h"
  22. #include "defines.h"
  23. #include "imports.h"
  24. #include "protos.h"
  25.  
  26.  /* Defines */
  27.  
  28. #define MOUSE_BUTTON_SELECT        (1 << 0)
  29. #define MOUSE_BUTTON_MENU        (1 << 1)
  30. #define MOUSE_BUTTON_RUBBER_BAND    (1 << 2)
  31.  
  32. #define PROJECT_TITLE_REFRESH_DELAY    500000        /* µs */
  33.  
  34.  /* Perform project action */
  35.  
  36. SHORT
  37. perform_project_action(VOID)
  38. {
  39.     struct Box *box = ¤t_box;
  40.     struct MsgPort *up = pwin->UserPort;
  41.     struct IntuiMessage *msg;
  42.     ULONG seconds = 0L, micros = 0L, last_seconds, last_micros;
  43.     SHORT status = EDITOR_STATUS_NORMAL;
  44.  
  45.     while (msg = IGetMsg(up))
  46.     {
  47.         struct Template *tp;
  48.         SHORT mouse_x, mouse_y, snap_x, snap_y;
  49.  
  50.         /* Get mouse position */
  51.         mouse_x = msg->MouseX;
  52.         mouse_y = msg->MouseY;
  53.         snap_x = (mouse_x + (snap_offset >> 1)) / snap_offset * snap_offset;
  54.         snap_y = (mouse_y + (snap_offset >> 1)) / snap_offset * snap_offset;
  55.         switch (msg->Class)
  56.         {
  57.         case MOUSEBUTTONS:
  58.             switch (msg->Code)
  59.             {
  60.             case SELECTDOWN:
  61.                 clear_template_info();
  62.                 switch (editor_mode)
  63.                 {
  64.                 case EDITOR_MODE_CREATE:
  65.                     box->bo_X1 = box->bo_X2 = snap_x;
  66.                     box->bo_Y1 = box->bo_Y2 = snap_y;
  67.                     mouse_button |= MOUSE_BUTTON_RUBBER_BAND;
  68.                     draw_box(pwin, box);
  69.                     break;
  70.  
  71.                 case EDITOR_MODE_MODIFY:
  72.                     if (get_template_by_pos(mouse_x, mouse_y))
  73.                     {
  74.                         draw_box(pwin, box);
  75.                         last_snap_x = snap_x;
  76.                         last_snap_y = snap_y;
  77.                         modify_mode = get_modify_mode(mouse_x, mouse_y);
  78.                         mouse_button |= MOUSE_BUTTON_RUBBER_BAND;
  79.                         print_template_info();
  80.                     }
  81.                     break;
  82.  
  83.                 case EDITOR_MODE_CLONE:
  84.                     if (get_template_by_pos(mouse_x, mouse_y))
  85.                     {
  86.                         draw_box(pwin, box);
  87.                         last_snap_x = snap_x;
  88.                         last_snap_y = snap_y;
  89.                         mouse_button |= MOUSE_BUTTON_RUBBER_BAND;
  90.                         print_template_info();
  91.                     }
  92.                     break;
  93.  
  94.                 case EDITOR_MODE_DELETE:
  95.                 case EDITOR_MODE_EDIT:
  96.                     if (get_template_by_pos(mouse_x, mouse_y))
  97.                     {
  98.                         mouse_button |= MOUSE_BUTTON_RUBBER_BAND;
  99.                         print_template_info();
  100.                     }
  101.                     break;
  102.                 }
  103.                 mouse_button |= MOUSE_BUTTON_SELECT;
  104.                 if (editor_mode != EDITOR_MODE_USE)
  105.                 {
  106.                     print_project_window_title();
  107.                 }
  108.                 break;
  109.  
  110.             case SELECTUP:
  111.                 tp = selected_template;
  112.                 switch (editor_mode)
  113.                 {
  114.                 case EDITOR_MODE_CREATE:
  115.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  116.                     {
  117.                         draw_box(pwin, box);
  118.                         box->bo_X2 = snap_x;
  119.                         box->bo_Y2 = snap_y;
  120.                         fix_template_bounds();
  121.                         end_rubber_banding();
  122.                     }
  123.                     break;
  124.  
  125.                 case EDITOR_MODE_MODIFY:
  126.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  127.                     {
  128.                         draw_box(pwin, box);
  129.                         clear_template_info();
  130.                         if (tp->tp_Flags & TEMPLATE_FLAG_MODIFIED)
  131.                         {
  132.                             tp->tp_Flags &= ~TEMPLATE_FLAG_MODIFIED;
  133.                             if (mouse_x < 0 || mouse_x > pwin->Width ||
  134.                                 mouse_y < 0 || mouse_y > pwin->Height)
  135.                             {
  136.                                 DisplayBeep((LONG) NULL);
  137.                             }
  138.                             else
  139.                             {
  140.                                 if (modify_mode == MODIFY_MODE_MOVE)
  141.                                 {
  142.                                     box->bo_X1 += snap_x - last_snap_x;
  143.                                     box->bo_Y1 += snap_y - last_snap_y;
  144.                                     box->bo_X2 += snap_x - last_snap_x;
  145.                                     box->bo_Y2 += snap_y - last_snap_y;
  146.                                 }
  147.                                 else
  148.                                 {
  149.                                     box->bo_X2 += snap_x - last_snap_x;
  150.                                     box->bo_Y2 += snap_y - last_snap_y;
  151.                                 }
  152.                                 fix_template_bounds();
  153.                                 end_rubber_banding();
  154.                             }
  155.                         }
  156.                     }
  157.                     break;
  158.  
  159.                 case EDITOR_MODE_CLONE:
  160.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  161.                     {
  162.                         draw_box(pwin, box);
  163.                         clear_template_info();
  164.                         if (mouse_x < 0 || mouse_x > pwin->Width ||
  165.                             mouse_y < 0 || mouse_y > pwin->Height)
  166.                         {
  167.                             DisplayBeep((LONG) NULL);
  168.                         }
  169.                         else
  170.                         {
  171.                             box->bo_X1 += snap_x - last_snap_x;
  172.                             box->bo_Y1 += snap_y - last_snap_y;
  173.                             box->bo_X2 += snap_x - last_snap_x;
  174.                             box->bo_Y2 += snap_y - last_snap_y;
  175.                             fix_template_bounds();
  176.                             end_rubber_banding();
  177.                         }
  178.                         tp->tp_Flags &= ~TEMPLATE_FLAG_MODIFIED;
  179.                     }
  180.                     break;
  181.  
  182.                 case EDITOR_MODE_DELETE:
  183.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  184.                     {
  185.                         clear_template_info();
  186.                         delete_template(selected_template);
  187.                     }
  188.                     break;
  189.  
  190.                 case EDITOR_MODE_EDIT:
  191.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  192.                     {
  193.                         info_template = NULL;
  194.                         info_displayed = FALSE;
  195.                         status = EDITOR_STATUS_EDIT;
  196.                     }
  197.                     break;
  198.                 }
  199.                 mouse_button &= ~(MOUSE_BUTTON_SELECT |
  200.                                   MOUSE_BUTTON_RUBBER_BAND);
  201.                 if (editor_mode != EDITOR_MODE_USE)
  202.                 {
  203.                     print_project_window_title();
  204.                     ActivateWindow(ewin);
  205.                 }
  206.                 break;
  207.  
  208.             case MENUDOWN:
  209.                 mouse_button |= MOUSE_BUTTON_MENU;
  210.                 break;
  211.  
  212.             case MENUUP:
  213.                 mouse_button &= ~MOUSE_BUTTON_MENU;
  214.                 ActivateWindow(ewin);
  215.                 break;
  216.             }
  217.             break;
  218.  
  219.         case MOUSEMOVE:
  220.             if (mouse_button & MOUSE_BUTTON_SELECT)
  221.             {
  222.  
  223.                 /* Save time for project title refresh delay while rubberbanding */
  224.                 tp = selected_template;
  225.                 last_seconds = seconds;
  226.                 last_micros = micros;
  227.                 seconds = msg->Seconds;
  228.                 micros = msg->Micros;
  229.                 switch (editor_mode)
  230.                 {
  231.                 case EDITOR_MODE_CREATE:
  232.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  233.                     {
  234.                         draw_box(pwin, box);
  235.                         box->bo_X2 = snap_x;
  236.                         box->bo_Y2 = snap_y;
  237.                         last_snap_x = snap_x;
  238.                         last_snap_y = snap_y;
  239.                         draw_box(pwin, box);
  240.                         if (seconds != last_seconds || (micros -
  241.                                                         last_micros) > PROJECT_TITLE_REFRESH_DELAY)
  242.                         {
  243.                             print_project_window_title();
  244.                         }
  245.                     }
  246.                     break;
  247.  
  248.                 case EDITOR_MODE_MODIFY:
  249.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  250.                     {
  251.                         draw_box(pwin, box);
  252.                         if (modify_mode == MODIFY_MODE_MOVE)
  253.                         {
  254.                             box->bo_X1 += snap_x - last_snap_x;
  255.                             box->bo_Y1 += snap_y - last_snap_y;
  256.                             box->bo_X2 += snap_x - last_snap_x;
  257.                             box->bo_Y2 += snap_y - last_snap_y;
  258.                         }
  259.                         else
  260.                         {
  261.                             box->bo_X2 += snap_x - last_snap_x;
  262.                             box->bo_Y2 += snap_y - last_snap_y;
  263.                         }
  264.                         last_snap_x = snap_x;
  265.                         last_snap_y = snap_y;
  266.                         draw_box(pwin, box);
  267.                         if (seconds != last_seconds || (micros -
  268.                                                         last_micros) > PROJECT_TITLE_REFRESH_DELAY)
  269.                         {
  270.                             print_project_window_title();
  271.                         }
  272.                         tp->tp_Flags |= TEMPLATE_FLAG_MODIFIED;
  273.                     }
  274.                     break;
  275.  
  276.                 case EDITOR_MODE_CLONE:
  277.                     if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  278.                     {
  279.                         draw_box(pwin, box);
  280.                         box->bo_X1 += snap_x - last_snap_x;
  281.                         box->bo_Y1 += snap_y - last_snap_y;
  282.                         box->bo_X2 += snap_x - last_snap_x;
  283.                         box->bo_Y2 += snap_y - last_snap_y;
  284.                         last_snap_x = snap_x;
  285.                         last_snap_y = snap_y;
  286.                         draw_box(pwin, box);
  287.                         if (seconds != last_seconds || (micros -
  288.                                                         last_micros) > PROJECT_TITLE_REFRESH_DELAY)
  289.                         {
  290.                             print_project_window_title();
  291.                         }
  292.                         tp->tp_Flags |= TEMPLATE_FLAG_MODIFIED;
  293.                     }
  294.                     break;
  295.  
  296.                 case EDITOR_MODE_DELETE:
  297.                 case EDITOR_MODE_EDIT:
  298.                     if (selected_template)
  299.                     {
  300.  
  301.                         /* Check if mouse points to selected template */
  302.                         if (find_template_by_pos(mouse_x, mouse_y) ==
  303.                             selected_template)
  304.                         {
  305.                             if (!(mouse_button & MOUSE_BUTTON_RUBBER_BAND))
  306.                             {
  307.                                 mouse_button |= MOUSE_BUTTON_RUBBER_BAND;
  308.                                 print_template_info();
  309.                                 print_project_window_title();
  310.                             }
  311.                         }
  312.                         else
  313.                         {
  314.                             if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  315.                             {
  316.                                 mouse_button &= ~MOUSE_BUTTON_RUBBER_BAND;
  317.                                 clear_template_info();
  318.                                 print_project_window_title();
  319.                             }
  320.                         }
  321.                     }
  322.                     break;
  323.                 }
  324.             }
  325.             break;
  326.  
  327.         case NEWSIZE:
  328.             refresh_all_templates();
  329.             ActivateWindow(ewin);
  330.             template_list.tl_Flags |= TEMPLATE_LIST_FLAG_CHANGED;
  331.             break;
  332.         }
  333.         IReplyMsg(msg);
  334.     }
  335.     return (status);
  336. }
  337.  
  338.  /* End rubber banding */
  339.  
  340. STATIC VOID
  341. end_rubber_banding(VOID)
  342. {
  343.     struct Box *box = ¤t_box;
  344.     USHORT type, min_width, min_height, width = box->bo_X2 - box->bo_X1 + 1, height = box->bo_Y2 - box->bo_Y1 + 1;
  345.  
  346.     /* First get current template type */
  347.     if (editor_mode == EDITOR_MODE_CREATE)
  348.     {
  349.         type = template_type;
  350.     }
  351.     else
  352.     {
  353.         type = selected_template->tp_Type;
  354.     }
  355.  
  356.     /* Now calc minimal dimension required for template */
  357.     switch (type)
  358.     {
  359.     case TEMPLATE_TYPE_SLIDER:
  360.     case TEMPLATE_TYPE_SCROLLER:
  361.     case TEMPLATE_TYPE_PALETTE:
  362.         if (width / 2 > height)
  363.         {
  364.             min_width = min_dimension[type].dim_Width;
  365.             min_height = min_dimension[type].dim_Height;
  366.         }
  367.         else
  368.         {
  369.             min_width = min_dimension[type].dim_Height * 2;
  370.             min_height = min_dimension[type].dim_Width / 2;
  371.         }
  372.         break;
  373.  
  374.     default:
  375.         min_width = min_dimension[type].dim_Width;
  376.         min_height = min_dimension[type].dim_Height;
  377.         break;
  378.     }
  379.  
  380.     /* Check template dimension is greater than minimal */
  381.     if (width < min_width || height < min_height)
  382.     {
  383.         DisplayBeep((LONG) NULL);
  384.     }
  385.     else
  386.     {
  387.         struct TemplateList *tl = &template_list;
  388.         struct Template *tp;
  389.         struct BorderData *bd;
  390.         struct TextData *td;
  391.         struct GadgetData *gd;
  392.  
  393.         switch (editor_mode)
  394.         {
  395.         case EDITOR_MODE_CREATE:
  396.             tp = create_template(tl);
  397.             display_template(tp);
  398.             break;
  399.  
  400.         case EDITOR_MODE_MODIFY:
  401.             tp = selected_template;
  402.             CopyMem((BYTE *) box, (BYTE *)
  403.                     & tp->tp_Box, (LONG) sizeof(struct Box));
  404.             /* Change template dimension */
  405.             switch (type)
  406.             {
  407.             case TEMPLATE_TYPE_BORDER:
  408.                 bd = &tp->tp_Data.tp_BorderData;
  409.                 bd->bd_LeftEdge = box->bo_X1;
  410.                 bd->bd_TopEdge = box->bo_Y1;
  411.                 bd->bd_Width = width;
  412.                 bd->bd_Height = height;
  413.                 break;
  414.  
  415.             case TEMPLATE_TYPE_TEXT:
  416.                 td = &tp->tp_Data.tp_TextData;
  417.                 td->td_LeftEdge = box->bo_X1;
  418.                 td->td_TopEdge = box->bo_Y1;
  419.  
  420.                 /* Calc size of text for template box */
  421.                 box = &tp->tp_Box;
  422.                 box->bo_X2 = box->bo_X1 + IPrintText(pri, pwin, td->td_Text,
  423.                                                      td->td_LeftEdge, td->td_TopEdge, td->td_Type,
  424.                                                      TEXT_DATA_FLAG_NO_PRINT, td->td_TextAttr) - 1;
  425.                 box->bo_Y2 = box->bo_Y1 + td->td_TextAttr->ta_YSize - 1;
  426.                 break;
  427.  
  428.             default:
  429.                 gd = &tp->tp_Data.tp_GadgetData;
  430.                 gd->gd_LeftEdge = box->bo_X1;
  431.                 gd->gd_TopEdge = box->bo_Y1;
  432.                 gd->gd_Width = width;
  433.                 gd->gd_Height = height;
  434.                 switch (gd->gd_Type)
  435.                 {
  436.                 case GADGET_DATA_TYPE_SLIDER:
  437.                     if (width / 2 < height)
  438.                     {
  439.                         gd->gd_Flags |= GADGET_DATA_FLAG_ORIENTATION_VERT;
  440.                     }
  441.                     else
  442.                     {
  443.                         gd->gd_Flags &= ~GADGET_DATA_FLAG_ORIENTATION_VERT;
  444.                     }
  445.                     break;
  446.  
  447.                 case GADGET_DATA_TYPE_SCROLLER:
  448.                     if (width / 2 < height)
  449.                     {
  450.                         gd->gd_Flags |= GADGET_DATA_FLAG_ORIENTATION_VERT;
  451.                     }
  452.                     else
  453.                     {
  454.                         gd->gd_Flags &= ~GADGET_DATA_FLAG_ORIENTATION_VERT;
  455.                     }
  456.                     break;
  457.  
  458.                 case GADGET_DATA_TYPE_PALETTE:
  459.                     if (width / 2 < height)
  460.                     {
  461.                         gd->gd_Flags |= GADGET_DATA_FLAG_PALETTE_INDICATOR_TOP;
  462.                     }
  463.                     else
  464.                     {
  465.                         gd->gd_Flags &= ~GADGET_DATA_FLAG_PALETTE_INDICATOR_TOP;
  466.                     }
  467.                     gd->gd_SpecialData.gd_PaletteData.gd_PaletteDepth = 2;
  468.                     gd->gd_SpecialData.gd_PaletteData.gd_PaletteColorOffset = 0;
  469.                     gd->gd_SpecialData.gd_PaletteData.gd_PaletteActiveColor = 2;
  470.                     break;
  471.                 }
  472.                 break;
  473.             }
  474.             refresh_all_templates();
  475.             break;
  476.  
  477.         case EDITOR_MODE_CLONE:
  478.             tp = clone_template(tl, selected_template, FALSE);
  479.             display_template(tp);
  480.             break;
  481.         }
  482.         template_list.tl_Flags |= TEMPLATE_LIST_FLAG_CHANGED;
  483.     }
  484. }
  485.  
  486.  /* Print project window title */
  487.  
  488. VOID
  489. print_project_window_title(VOID)
  490. {
  491.     struct Box *box = ¤t_box;
  492.     BYTE *title = &project_window_title[0];
  493.     USHORT width, height;
  494.  
  495.     if (box->bo_X2 > box->bo_X1)
  496.     {
  497.         width = box->bo_X2 - box->bo_X1 + 1;
  498.     }
  499.     else
  500.     {
  501.         width = box->bo_X1 - box->bo_X2 + 1;
  502.     }
  503.     if (box->bo_Y2 > box->bo_Y1)
  504.     {
  505.         height = box->bo_Y2 - box->bo_Y1 + 1;
  506.     }
  507.     else
  508.     {
  509.         height = box->bo_Y1 - box->bo_Y2 + 1;
  510.     }
  511.     switch (editor_mode)
  512.     {
  513.     case EDITOR_MODE_CREATE:
  514.         if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  515.         {
  516.             sprintf(title, " Left=%d Top=%d Width=%d Height=%d ",
  517.                     box->bo_X1, box->bo_Y1, width, height);
  518.         }
  519.         else
  520.         {
  521.             sprintf(title, " Create %s Template ",
  522.                     template_type_text_array[template_type]);
  523.         }
  524.         break;
  525.  
  526.     case EDITOR_MODE_MODIFY:
  527.         if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  528.         {
  529.             sprintf(title, " Left=%d Top=%d Width=%d Height=%d ",
  530.                     box->bo_X1, box->bo_Y1, width, height);
  531.         }
  532.         else
  533.         {
  534.             strcpy(title, " Modify Template ");
  535.         }
  536.         break;
  537.  
  538.     case EDITOR_MODE_DELETE:
  539.         if (mouse_button & MOUSE_BUTTON_RUBBER_BAND)
  540.         {
  541.             sprintf(title, " Left=%d Top=%d Width=%d Height=%d ",
  542.                     box->bo_X1, box->bo_Y1, width, height);
  543.         }
  544.         else
  545.         {
  546.             strcpy(title, " Delete Template ");
  547.         }
  548.         break;
  549.  
  550.     case EDITOR_MODE_EDIT:
  551.         strcpy(title, " Edit Template ");
  552.         break;
  553.  
  554.     case EDITOR_MODE_USE:
  555.         strcpy(title, " Use Templates ");
  556.         break;
  557.     }
  558.     SetWindowTitles(pwin, title, (LONG) NULL);
  559. }
  560.  
  561.  /* Start a new project */
  562.  
  563. SHORT
  564. new_project(struct TemplateList *tl, USHORT new_flags)
  565. {
  566.     SHORT status;
  567.  
  568.     /* Free all templates */
  569.     free_template_list(tl);
  570.     ISetGadgetAttributes(egl, EDITOR_GADGET_TEMPLATES, 0L, 0L,
  571.                          USE_CURRENT_VALUE, USE_CURRENT_VALUE, &tl->tl_Templates);
  572.     clear_template_info();
  573.  
  574.     /* Use default project name? */
  575.     if (new_flags & TEMPLATE_LIST_FLAG_DEFAULT_WINDOW)
  576.     {
  577.         change_project_name(tl, DEFAULT_PROJECT_NAME, -1);
  578. /*      strcpy(project_file_requester->fr_File, DEFAULT_PROJECT_FILE_NAME); */
  579.     }
  580.  
  581.     /* Close old project window and open new one */
  582.     if ((status = new_project_window(tl, new_flags)) == EDITOR_STATUS_NORMAL)
  583.     {
  584.         print_project_window_title();
  585.     }
  586.     show_error(status);
  587.     return (status);
  588. }
  589.  
  590.  /* Close old project window and open new one */
  591.  
  592. SHORT
  593. new_project_window(struct TemplateList * tl, USHORT new_flags)
  594. {
  595.     struct NewWindow *nwin = &project_new_window;
  596.     USHORT flags;
  597.     SHORT status;
  598.  
  599.     /* Use default template list data? */
  600.     if (new_flags & TEMPLATE_LIST_FLAG_DEFAULT_WINDOW)
  601.     {
  602.         nwin->LeftEdge = 0;
  603.         nwin->TopEdge = ewin->Height + 1;
  604.         nwin->Width = wb_screen.Width;
  605.         nwin->Height = wb_screen.Height - nwin->TopEdge;
  606.         new_flags = tl->tl_Flags = DEFAULT_TEMPLATE_LIST_FLAGS;
  607.     }
  608.  
  609.     /* Change render info */
  610.     if (pri)
  611.     {
  612.         IFreeRenderInfo(pri);
  613.     }
  614.  
  615.     flags = PROJECT_RENDER_INFO_FLAGS |
  616.         (new_flags & TEMPLATE_LIST_FLAG_BACK_FILL ? RENDER_INFO_FLAG_BACK_FILL : 0) |
  617.         (new_flags & TEMPLATE_LIST_FLAG_AVAIL_FONTS ? RENDER_INFO_FLAG_AVAIL_FONTS : 0);
  618.  
  619.     if (!(pri = IGetRenderInfo((struct Screen *) NULL, flags)))
  620.         status = EDITOR_ERROR_OUT_OF_MEM;
  621.     else
  622.     {
  623.         /* Change new window structure */
  624.  
  625.         if (new_flags & TEMPLATE_LIST_FLAG_RENDER_COLORS)
  626.             flags = PROJECT_OPEN_WINDOW_FLAGS | OPEN_WINDOW_FLAG_RENDER_PENS;
  627.         else
  628.             flags = PROJECT_OPEN_WINDOW_FLAGS;
  629.  
  630.         /* Open new project window */
  631.         if (pwin)
  632.             ICloseWindow(pwin, FALSE);
  633.  
  634.         if (!(pwin = IOpenWindow(pri, nwin, flags)))
  635.             status = EDITOR_ERROR_NO_WINDOW;
  636.         else
  637.         {
  638.             print_project_window_title();
  639.             status = EDITOR_STATUS_NORMAL;
  640.         }
  641.     }
  642.  
  643.     show_error(status);
  644.     return (status);
  645. }
  646.  
  647.  /* Clear project window */
  648.  
  649. VOID
  650. clear_project_window(USHORT flags)
  651. {
  652.     SetRast(pwin->RPort, 0L);
  653.     RefreshWindowFrame(pwin);
  654.     if (flags & TEMPLATE_LIST_FLAG_BACK_FILL)
  655.     {
  656.         IClearWindow(pri, pwin, 0, 0, (USHORT) - 1, (USHORT) - 1, 0);
  657.     }
  658. }
  659.  
  660.  /* Change project name and display it as window title */
  661.  
  662. VOID
  663. change_project_name(struct TemplateList *tl, BYTE * new_name, SHORT len)
  664. {
  665.     BYTE *name = &tl->tl_ProjectName[0], *title = &editor_window_title[0];
  666.  
  667.     if (len < 0)
  668.     {
  669.         len = strlen(new_name);
  670.     }
  671.     if (len > MAX_PROJECT_NAME_LEN)
  672.     {
  673.         len = MAX_PROJECT_NAME_LEN;
  674.     }
  675.  
  676. #ifdef LATTICE_50
  677.     strncpy(name, new_name, (int) len);
  678. #else
  679.     strncpy(name, new_name, (size_t) len);
  680. #endif
  681.  
  682.     *(name + len) = '\0';
  683.     sprintf(title, " %s ", name);
  684.     SetWindowTitles(ewin, title, (BYTE *) - 1L);
  685. }
  686.